﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>第三种验证码测试方式</title>
    <script src="jquery-1.8.0.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#btnLogin").click(function () {
                if ($("#txtVerifyCode").val().trim().length != 4) {
                    alert("请输入验证码!");
                    $("#txtVerifyCode").focus();
                    return false;
                }
                var validateCode = $("#txtVerifyCode").val().trim();
                var userName = $("#txtUserName").val().trim();
                var userPwd = $("#txtUserPwd").val().trim();
                $.post("ajaxHandlerValidateCode.ashx", { "validateCode": validateCode, "userName": userName, "userPwd": userPwd, "TimesDemo": new Date() }, function (data, state) {
                    if (state == "success") {
                        var tempBl = true;
                        switch (data) {
                            case "0":
                                alert("验证码错误！");
                                $("#txtVerifyCode").focus();
                                $("#imgValidateCode").attr("src", "VerifyCode2.ashx?parmTemp=" + new Date().toTimeString());
                                tempBl = false;
                                break;
                            case "1":
                                tempBl = true;
                                window.location.href = "webMain.aspx";
                                break;
                            case "2":
                                alert("用户名不存在！");
                                $("#txtUserName").focus();
                                tempBl = false;
                                break;
                            case "3":
                                alert("密码错误！");
                                $("#txtUserPwd").focus();
                                tempBl = false;
                                break;
                            default:
                                alert("系统错误！");
                                $("#txtUserName").focus();
                                tempBl = false;
                                break;
                        }
                        return tempBl;
                    }
                });
            })
        })
    </script>
</head>
<body>
    <form action="" name="fm1" method="post">
    <div>
        <ul>
            <li><span style="color: Gray">用户名、密码默认是: 张三,zhangsan</span>
                <br />
                用户名:<input type="text" name="txtUserName" id="txtUserName" value="张三" />
                <br />
                密&nbsp;&nbsp;码:<input type="password" name="txtUserPwd" id="txtUserPwd" value="zhangsan" />
                <br />
                验证码:<input id="txtVerifyCode" type="text" maxlength="4" name="txtVerifyCode" />
                <img alt="验证码" id="imgValidateCode" src="VerifyCode2.ashx" title="点击更换验证码" style="cursor: pointer;"
                    onclick="this.src=this.src+'?'" />
                <br />
                <input type="button" name="btnLogin" id="btnLogin" value="登录" style="margin-left: 40px;" />
            </li>
            <li>
                <div id="divTemp">
                </div>
            </li>
        </ul>
    </div>
    </form>
</body>
</html>
